﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SvnMonitor
{
    static class MonitorData
    {
        public static event EventHandler Changed;

        private static readonly HashSet<string> changedRepositories = new HashSet<string>();

        public static bool IsChanged(string workingCopy)
        {
            if (changedRepositories.Contains(workingCopy))
                return true;

            return false;
        }

        public static bool HasChanges()
        {
            return changedRepositories.Any();
        }

        public static void MarkAsUnchanged(string workingCopy)
        {
            if (changedRepositories.Remove(workingCopy))
                raiseChanged();
        }

        public static void MarkAsChanged(string workingCopy)
        {
            if (changedRepositories.Add(workingCopy))
                raiseChanged();
        }

        private static void raiseChanged()
        {
            var handler = Changed;
            if (handler != null)
                handler.Invoke(null, EventArgs.Empty);
        }
    }
}
